package com.aier.common.common;

import java.util.List;

import com.aier.common.service.ISysPhoneMessageService;

public class SendSchoolPhoneMessage extends Thread {

    private List<List<String>> userPhoneList;// List<String>["手机号","uid","是否教师:1是/0否"]
    private String message;
    private Integer sid;
    private ISysPhoneMessageService sysPhoneMessageService;
    private Integer type;
    private Long relativeid;
    private Integer size;
    private Long tid;

    public SendSchoolPhoneMessage() {
        super();
    }
    

    public SendSchoolPhoneMessage(List<List<String>> userPhoneList,
            String message, Integer sid,
            ISysPhoneMessageService sysPhoneMessageService,Integer type,Long relativeid,Integer size,Long tid) {
        super();
        this.userPhoneList = userPhoneList;
        this.message = message;
        this.sid = sid;
        this.sysPhoneMessageService = sysPhoneMessageService;
        this.type = type;
        this.relativeid = relativeid;
        this.size = size;
        this.tid = tid;
    }



    @Override
    public void run() {
        try {
            // 教师 uid
            for(List<String> upList:userPhoneList){
                String phone = upList.get(0);
                Long uid = Long.valueOf(upList.get(1));
                String isteacher = upList.get(2);
                //message = InviteRequestUtil.getFilterMessage(message);
                //String new_message = message + "登陆www.aier360.com查看详情【爱儿360】";
                
                // 根据学校id查询学校的缴费方式
                int method = sysPhoneMessageService.searchSchoolBuyMethodBySid(sid);
                if (method == 1) {
                    if("1".equals(isteacher)){//是教师
                        //sysPhoneMessageService.insertSchoolPhoneMessage(phone, message,sid,uid,type,relativeid);
                        sysPhoneMessageService.insertSchoolPhoneMessageMobile(phone, message,sid,uid,type,relativeid);
                    }else{//是用户(家长)
                        //1是否交费用户...
                        int user_edate_num = sysPhoneMessageService.countUserEdateNum(uid);
                        if(user_edate_num>0){
                            //sysPhoneMessageService.insertSchoolPhoneMessage(phone, message,sid,uid,type,relativeid);
                            sysPhoneMessageService.insertSchoolPhoneMessageMobile(phone, message,sid,uid,type,relativeid);
                        }
                    }
                } else {
                    //boolean flag = sysPhoneMessageService.insertSchoolPhoneMessage(phone, message,sid,uid,type,relativeid);
                    boolean flag = sysPhoneMessageService.insertSchoolPhoneMessageMobile(phone, message,sid,uid,type,relativeid);
                    if (flag) {
                        sysPhoneMessageService.updateTeacherMessageCount(tid,size);
                    }
                }
                
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    };

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setSysPhoneMessageService(
            ISysPhoneMessageService sysPhoneMessageService) {
        this.sysPhoneMessageService = sysPhoneMessageService;
    }

    public List<List<String>> getUserPhoneList() {
        return userPhoneList;
    }

    public void setUserPhoneList(List<List<String>> userPhoneList) {
        this.userPhoneList = userPhoneList;
    }

    public Integer getSid() {
        return sid;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public ISysPhoneMessageService getSysPhoneMessageService() {
        return sysPhoneMessageService;
    }


    public Integer getType() {
        return type;
    }


    public void setType(Integer type) {
        this.type = type;
    }


    public Long getRelativeid() {
        return relativeid;
    }


    public void setRelativeid(Long relativeid) {
        this.relativeid = relativeid;
    }


    public Integer getSize() {
        return size;
    }


    public void setSize(Integer size) {
        this.size = size;
    }


    public Long getTid() {
        return tid;
    }


    public void setTid(Long tid) {
        this.tid = tid;
    }
}
